package com.javelingroup.data;

import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class LoadFile {
	
	public static String FILENAME = "resource/listForWebApp.txt";
    
    List<Data> data = new ArrayList<Data>();
    
    File pathToFile = new File(FILENAME);
    
    public List<Data> ReadFile() {
        
        ClassLoader classLoader = this.getClass().getClassLoader();
        InputStream resourceAsStream = classLoader.getResourceAsStream(FILENAME);
        Scanner sc = null;
        List<Data> result = new ArrayList<Data>();
        try {
            sc = new Scanner(resourceAsStream);
            
            while(sc.hasNext()){
                result.add(new Data(sc.nextLine()));
            }
        }finally{
            if (sc != null)
                sc.close();
        } 
        
        return result;
//        
//        FileReader fileReader = null;
//        
//        try{
//            fileReader = new FileReader(filePath);
//        }catch(Exception e){};
//        
//        BufferedReader bufferedReader = new BufferedReader(fileReader);
//        
//        String line = null;
//        
//        try {
//            while ((line = bufferedReader.readLine() ) != null) {
//                data.add( new Data(line));
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        
    }
    
    public List<Data> getData(){
        return data;
    }

}
